package com.codi.bus.core.service.util;

import com.codi.base.util.*;
import com.codi.bus.constant.GlobalConstant;
import com.codi.bus.core.domain.Lookup;
import com.codi.bus.core.domain.OrganBank;
import com.codi.bus.core.domain.UserBank;
import com.codi.bus.core.resultModel.*;
import com.codi.bus.core.service.impl.QueryServiceImpl;
import com.codi.bus.core.service.model.*;
import com.codi.bus.exception.BaseException;
import com.codi.bus.util.IdCardUtil;
import com.codi.fcloud.ufx.constant.HSOutputParameterNames;
import com.codi.fcloud.ufx.constant.HsConst;
import com.codi.message.constant.ErrorConstant;
import com.codi.trade.response.HsCombTransferTradeResponse;
import com.google.common.base.Strings;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.util.CollectionUtils;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class ModelPopulateUtils {

    private static final Logger logger = LoggerFactory.getLogger(QueryServiceImpl.class);

    /**
     * 组合投资交易
     *
     * @param list
     * @param result
     * @param tradeLookups
     * @param bankLookups
     * @param isOrg
     * @return
     */
    public static List<PortfolioSummaryQryModel> portfolioApply(List<Map<String, Object>> list, PortfolioSummaryResult result,
                                                                List<Lookup> tradeLookups, List<Lookup> bankLookups, Boolean isOrg) {
        List<PortfolioSummaryQryModel> portfolioSummaryQryModels = new ArrayList<>();
        for (Map<String, Object> item : list) {
            PortfolioSummaryQryModel model = new PortfolioSummaryQryModel();
            // 记录数
            String rowCount = item.get(HSOutputParameterNames.ROWCOUNT).toString();
            if (!StringUtil.isEmpty(rowCount)) {
                result.setRowCount(Long.parseLong(rowCount));
            } else {
                return portfolioSummaryQryModels;
            }
            // 总记录数
            String totalCount = item.get(HSOutputParameterNames.TOTAL_COUNT).toString();
            if (!StringUtil.isEmpty(totalCount)) {
                result.setTotalCount(Long.parseLong(totalCount));
            }

            // 过滤掉撤单申请交易
            model.setFundBusinCode(item.get(HSOutputParameterNames.FUND_BUSIN_CODE).toString());
            if (model.getFundBusinCode().equals(GlobalConstant.FUND_BUSIN_CODE_APPLY_UNDO)) {
                continue;
            }

            model.setBalance(BigDecimalUtil.ConvertToBigDecimal(item.get(HSOutputParameterNames.BALANCE).toString()));
            model.setCapitalMode(item.get(HSOutputParameterNames.CAPITAL_MODE).toString());
            model.setPortfolioAllotNo(item.get(HSOutputParameterNames.PORTFOLIO_ALLOT_NO).toString());
            model.setCustPortfolioCode(item.get(HSOutputParameterNames.CUST_PORTFOLIO_CODE).toString());
            model.setPortfolioAllotNo(item.get(HSOutputParameterNames.PORTFOLIO_ALLOT_NO).toString());
            model.setProtocolName(item.get(HSOutputParameterNames.PROTOCOL_NAME).toString());
            model.setTradeAccount(item.get(HSOutputParameterNames.TRADE_ACCO).toString());
            // 设置交易业务名称
            if (tradeLookups != null) {
                for (Lookup lookup : tradeLookups) {
                    if (lookup.getRuleValue().equals(model.getFundBusinCode())) {
                        model.setFundBusinName(lookup.getRuleText());
                        break;
                    }
                }
            }

//            // 设置银行名称
//            if (bankLookups != null) {
//                for (Lookup lookup : bankLookups) {
//                    if (lookup.getRuleValue().equals(model.getBankHSCode())) {
//                        model.setBankName(lookup.getRuleText());
//                        break;
//                    }
//                }
//            }
            model.setIsOrg(isOrg);
            portfolioSummaryQryModels.add(model);
        }

        return portfolioSummaryQryModels;
    }


    /**
     * 普通基金份额明细查询
     */
    public static List<ShareDetailQryModel> populateShareDetailQryFund(List<Map<String, Object>> list, UserBank userBank) {
        List<ShareDetailQryModel> shareDetailQryModels = new ArrayList<>();

        for (Map<String, Object> item : list) {
            if (!userBank.getExternalTradeAccount().equals(item.get(HSOutputParameterNames.TRADE_ACCO))) {
                continue;
            }
            ShareDetailQryModel model = new ShareDetailQryModel();
            // 记录数
            String rowCount = item.get(HSOutputParameterNames.ROWCOUNT).toString();
            if (!StringUtil.isEmpty(rowCount)) {
                model.setRowcount(Long.parseLong(rowCount));
            } else {
                return shareDetailQryModels;
            }
            // 总记录数
            String totalCount = item.get(HSOutputParameterNames.TOTAL_COUNT).toString();
            if (!StringUtil.isEmpty(totalCount)) {
                model.setTotalCount(Long.parseLong(totalCount));
            }
            model.setAffirmDate(item.get(HSOutputParameterNames.AFFIRM_DATE).toString());
            model.setBusinessFrozenAmount(BigDecimalUtil.ConvertToBigDecimal(item.get(HSOutputParameterNames.BUSINESS_FROZEN_AMOUNT).toString()));
            model.setEnableShares(BigDecimalUtil.ConvertToBigDecimal(item.get(HSOutputParameterNames.ENABLE_SHARES).toString()));
            model.setFundBusinCode(item.get(HSOutputParameterNames.FUND_BUSIN_CODE).toString());
            model.setFundCode(item.get(HSOutputParameterNames.FUND_CODE).toString());
            model.setIncomeFloat(BigDecimalUtil.ConvertToBigDecimal(item.get(HSOutputParameterNames.INCOME_FLOAT).toString()));
            model.setNetValue(BigDecimalUtil.ConvertToBigDecimal(item.get(HSOutputParameterNames.NET_VALUE).toString()));
            model.setPortfolioCode(item.get(HSOutputParameterNames.PORTFOLIO_CODE).toString());
            //logger.debug("--------基金 确认日期：{}, 基金编码：{}， 可用份额：{}",model.getAffirmDate(),model.getFundCode(),model.getEnableShares());
            try {
                if (item.get(HSOutputParameterNames.REG_DATE) != null && StringUtils.isNotBlank(item.get(HSOutputParameterNames.REG_DATE).toString())) {
                    model.setRegDate(DateUtils.stringToDate4(item.get(HSOutputParameterNames.REG_DATE).toString()));
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
            try {
                if (item.get(HSOutputParameterNames.SHAREEXPIRE_DATE) != null && StringUtils.isNotBlank(item.get(HSOutputParameterNames.SHAREEXPIRE_DATE).toString())) {
                    model.setShareexpireDate(DateUtils.stringToDate4(item.get(HSOutputParameterNames.SHAREEXPIRE_DATE).toString()));
                }
            } catch (Exception e) {
                e.printStackTrace();
            }

            model.setShareType(item.get(HSOutputParameterNames.SHARE_TYPE).toString());
            model.setSuccessType(item.get(HSOutputParameterNames.SUCCESS_TYPE).toString());
            model.setTaAccount(item.get(HSOutputParameterNames.TA_ACCO).toString());
            model.setTaSerialId(item.get(HSOutputParameterNames.TA_SERIAL_ID).toString());
            model.setTradeAccount(item.get(HSOutputParameterNames.TRADE_ACCO).toString());
            model.setUnpaidIncome(BigDecimalUtil.ConvertToBigDecimal(item.get(HSOutputParameterNames.UNPAID_INCOME).toString()));
            shareDetailQryModels.add(model);
        }

        return shareDetailQryModels;
    }

    /**
     * 普通基金份额明细查询   机构
     */
    public static List<ShareDetailQryModel> populateOrganShareDetailQryFund(List<Map<String, Object>> list, OrganBank organBank) {
        List<ShareDetailQryModel> shareDetailQryModels = new ArrayList<>();

        for (Map<String, Object> item : list) {
            if (!organBank.getExternalTradeAccount().equals(item.get(HSOutputParameterNames.TRADE_ACCO))) {
                continue;
            }
            ShareDetailQryModel model = new ShareDetailQryModel();
            // 记录数
            String rowCount = item.get(HSOutputParameterNames.ROWCOUNT).toString();
            if (!StringUtil.isEmpty(rowCount)) {
                model.setRowcount(Long.parseLong(rowCount));
            } else {
                return shareDetailQryModels;
            }
            // 总记录数
            String totalCount = item.get(HSOutputParameterNames.TOTAL_COUNT).toString();
            if (!StringUtil.isEmpty(totalCount)) {
                model.setTotalCount(Long.parseLong(totalCount));
            }
            model.setAffirmDate(item.get(HSOutputParameterNames.AFFIRM_DATE).toString());
            model.setBusinessFrozenAmount(BigDecimalUtil.ConvertToBigDecimal(item.get(HSOutputParameterNames.BUSINESS_FROZEN_AMOUNT).toString()));
            model.setEnableShares(BigDecimalUtil.ConvertToBigDecimal(item.get(HSOutputParameterNames.ENABLE_SHARES).toString()));
            model.setFundBusinCode(item.get(HSOutputParameterNames.FUND_BUSIN_CODE).toString());
            model.setFundCode(item.get(HSOutputParameterNames.FUND_CODE).toString());
            model.setIncomeFloat(BigDecimalUtil.ConvertToBigDecimal(item.get(HSOutputParameterNames.INCOME_FLOAT).toString()));
            model.setNetValue(BigDecimalUtil.ConvertToBigDecimal(item.get(HSOutputParameterNames.NET_VALUE).toString()));
            model.setPortfolioCode(item.get(HSOutputParameterNames.PORTFOLIO_CODE).toString());
            try {
                model.setRegDate(DateUtils.stringToDate4(item.get(HSOutputParameterNames.REG_DATE).toString()));
            } catch (Exception e) {
                e.printStackTrace();
            }
            try {
                model.setShareexpireDate(DateUtils.stringToDate4(item.get(HSOutputParameterNames.SHAREEXPIRE_DATE).toString()));
            } catch (Exception e) {
                e.printStackTrace();
            }

            model.setShareType(item.get(HSOutputParameterNames.SHARE_TYPE).toString());
            model.setTaAccount(item.get(HSOutputParameterNames.TA_ACCO).toString());
            model.setSuccessType(item.get(HSOutputParameterNames.SUCCESS_TYPE).toString());
            model.setTaSerialId(item.get(HSOutputParameterNames.TA_SERIAL_ID).toString());
            model.setTradeAccount(item.get(HSOutputParameterNames.TRADE_ACCO).toString());
            model.setUnpaidIncome(BigDecimalUtil.ConvertToBigDecimal(item.get(HSOutputParameterNames.UNPAID_INCOME).toString()));
            shareDetailQryModels.add(model);
        }

        return shareDetailQryModels;
    }

    /**
     * 组合份额明细查询
     */
    public static List<ShareDetailQryModel> populateShareDetailQryPorefolio(List<Map<String, Object>> list, List<String> tradeAccounts) {
        List<ShareDetailQryModel> shareDetailQryModels = new ArrayList<>();
        for (Map<String, Object> item : list) {
            if (item.get(HSOutputParameterNames.TRADE_ACCO) == null) {
                continue;
            }
            if (tradeAccounts.contains(item.get(HSOutputParameterNames.TRADE_ACCO).toString())) {
                continue;
            }
            ShareDetailQryModel model = new ShareDetailQryModel();
            // 记录数
            String rowCount = item.get(HSOutputParameterNames.ROWCOUNT).toString();
            if (!StringUtil.isEmpty(rowCount)) {
                model.setRowcount(Long.parseLong(rowCount));
            } else {
                return shareDetailQryModels;
            }
            // 总记录数
            String totalCount = item.get(HSOutputParameterNames.TOTAL_COUNT).toString();
            if (!StringUtil.isEmpty(totalCount)) {
                model.setTotalCount(Long.parseLong(totalCount));
            }
            model.setAffirmDate(item.get(HSOutputParameterNames.AFFIRM_DATE).toString());
            model.setBusinessFrozenAmount(BigDecimalUtil.ConvertToBigDecimal(item.get(HSOutputParameterNames.BUSINESS_FROZEN_AMOUNT).toString()));
            model.setEnableShares(BigDecimalUtil.ConvertToBigDecimal(item.get(HSOutputParameterNames.ENABLE_SHARES).toString()));
            model.setFundBusinCode(item.get(HSOutputParameterNames.FUND_BUSIN_CODE).toString());
            model.setFundCode(item.get(HSOutputParameterNames.FUND_CODE).toString());
            model.setIncomeFloat(BigDecimalUtil.ConvertToBigDecimal(item.get(HSOutputParameterNames.INCOME_FLOAT).toString()));
            model.setNetValue(BigDecimalUtil.ConvertToBigDecimal(item.get(HSOutputParameterNames.NET_VALUE).toString()));
            model.setPortfolioCode(item.get(HSOutputParameterNames.PORTFOLIO_CODE).toString());
            try {
                model.setRegDate(DateUtils.stringToDate4(item.get(HSOutputParameterNames.REG_DATE).toString()));
            } catch (Exception e) {
                e.printStackTrace();
            }
            try {
                model.setShareexpireDate(DateUtils.stringToDate4(item.get(HSOutputParameterNames.SHAREEXPIRE_DATE).toString()));
            } catch (Exception e) {
                e.printStackTrace();
            }

            model.setShareType(item.get(HSOutputParameterNames.SHARE_TYPE).toString());
            model.setSuccessType(item.get(HSOutputParameterNames.SUCCESS_TYPE).toString());
            model.setTaAccount(item.get(HSOutputParameterNames.TA_ACCO).toString());
            model.setTaSerialId(item.get(HSOutputParameterNames.TA_SERIAL_ID).toString());
            model.setTradeAccount(item.get(HSOutputParameterNames.TRADE_ACCO).toString());
            model.setUnpaidIncome(BigDecimalUtil.ConvertToBigDecimal(item.get(HSOutputParameterNames.UNPAID_INCOME).toString()));
            //logger.debug("确认日期：{},基金编码：{}，可用份额：{}，组合编码：{}",model.getAffirmDate(),model.getFundCode(),model.getEnableShares(),model.getPortfolioCode());
            shareDetailQryModels.add(model);
        }
        return shareDetailQryModels;
    }

    /**
     * 组合份额查询
     *
     * @param list
     * @return
     */
    public static List<SharePortfolioCodeQryModel> populateSharePortfolioCodeQry(List<Map<String, Object>> list) {
        List<SharePortfolioCodeQryModel> sharePortfolioCodeQryModels = new ArrayList<>();
        for (Map<String, Object> item : list) {
            SharePortfolioCodeQryModel model = new SharePortfolioCodeQryModel();
            // 记录数
            String rowCount = item.get(HSOutputParameterNames.ROWCOUNT).toString();
            if (!StringUtil.isEmpty(rowCount)) {
                model.setRowCount(Long.parseLong(rowCount));
            } else {
                return sharePortfolioCodeQryModels;
            }
            // 总记录数
            String totalCount = item.get(HSOutputParameterNames.TOTAL_COUNT).toString();
            if (!StringUtil.isEmpty(totalCount)) {
                model.setTotalCount(Long.parseLong(totalCount));
            }
            model.setBusinessFrozenAmount(BigDecimalUtil.ConvertToBigDecimal(item.get(HSOutputParameterNames.BUSINESS_FROZEN_AMOUNT).toString()));
            model.setCustType(item.get(HSOutputParameterNames.CUST_TYPE).toString());
            model.setEnableShares(BigDecimalUtil.ConvertToBigDecimal(item.get(HSOutputParameterNames.ENABLE_SHARES).toString()));
            model.setFundCode(item.get(HSOutputParameterNames.FUND_CODE).toString());
            model.setFundShare(BigDecimalUtil.ConvertToBigDecimal(item.get(HSOutputParameterNames.FUND_SHARE).toString()));
            model.setPortfolioAllotNo(item.get(HSOutputParameterNames.PORTFOLIO_ALLOT_NO).toString());
            model.setPortfolioCode(item.get(HSOutputParameterNames.PORTFOLIO_CODE).toString());
            model.setShareType(item.get(HSOutputParameterNames.SHARE_TYPE).toString());
            model.setTaSerialId(item.get(HSOutputParameterNames.TA_SERIAL_ID).toString());
            model.setTradeAccount(item.get(HSOutputParameterNames.TRADE_ACCO).toString());
            sharePortfolioCodeQryModels.add(model);
        }
        return sharePortfolioCodeQryModels;
    }

    /**
     * 组合投资收益查询
     *
     * @param list
     * @return
     */
    public static Map<String, CombIncomeQryModel> populateCombIncomeQry(List<Map<String, Object>> list) {
        List<CombIncomeQryModel> combIncomeQryModels = new ArrayList<>();
        Map<String, CombIncomeQryModel> modelMap = new HashMap<>();
        for (Map<String, Object> item : list) {
            CombIncomeQryModel model = new CombIncomeQryModel();
            // 记录数
            String rowCount = item.get(HSOutputParameterNames.ROWCOUNT).toString();
            if (!StringUtil.isEmpty(rowCount)) {
                model.setRowcount(Long.parseLong(rowCount));
            } else {
                return modelMap;
            }
            // 总记录数
            String totalCount = item.get(HSOutputParameterNames.TOTAL_COUNT).toString();
            if (!StringUtil.isEmpty(totalCount)) {
                model.setTotalCount(Long.parseLong(totalCount));
            }
            model.setCombIncome(BigDecimalUtil.ConvertToBigDecimal(item.get(HSOutputParameterNames.COMB_INCOME).toString()));
            model.setCombSumAsset(BigDecimalUtil.ConvertToBigDecimal(item.get(HSOutputParameterNames.COMB_SUM_ASSET).toString()));
            model.setCombSumIncome(BigDecimalUtil.ConvertToBigDecimal(item.get(HSOutputParameterNames.COMB_SUM_INCOME).toString()));
            model.setExtCombcode(item.get(HSOutputParameterNames.EXT_COMBCODE).toString());
            model.setTradeAcco(item.get(HSOutputParameterNames.TRADE_ACCO).toString());
            modelMap.put(model.getExtCombcode(), model);
            //combIncomeQryModels.add(model);
        }
        return modelMap;
    }

    /**
     * 组合投资份额查询
     *
     * @param list
     * @return
     */
    public static List<CombSharesQryModel> populateCombSharesQry(List<Map<String, Object>> list) {
        List<CombSharesQryModel> combSharesQryModels = new ArrayList<>();
        for (Map<String, Object> item : list) {
            CombSharesQryModel model = new CombSharesQryModel();
            // 记录数
            String rowCount = item.get(HSOutputParameterNames.ROWCOUNT).toString();
            if (!StringUtil.isEmpty(rowCount)) {
                model.setRowcount(Long.parseLong(rowCount));
            } else {
                return combSharesQryModels;
            }
            // 总记录数
            String totalCount = item.get(HSOutputParameterNames.TOTAL_COUNT).toString();
            if (!StringUtil.isEmpty(totalCount)) {
                model.setTotalCount(Long.parseLong(totalCount));
            }
            model.setCustType(item.get(HSOutputParameterNames.CUST_TYPE).toString());
            model.setEnableShares(BigDecimalUtil.ConvertToBigDecimal(item.get(HSOutputParameterNames.ENABLE_SHARES).toString()));
            model.setFrozenShares(BigDecimalUtil.ConvertToBigDecimal(item.get(HSOutputParameterNames.FROZEN_SHARES).toString()));
            model.setFundCode(item.get(HSOutputParameterNames.FUND_CODE).toString());
            model.setFundShare(BigDecimalUtil.ConvertToBigDecimal(item.get(HSOutputParameterNames.FUND_SHARE).toString()));
            model.setNew_portfolioCode(item.get(HSOutputParameterNames.NEW_PORTFOLIO_CODE).toString());
            model.setPortfolioCode(item.get(HSOutputParameterNames.PORTFOLIO_CODE).toString());
            model.setTradeAcco(item.get(HSOutputParameterNames.TRADE_ACCO).toString());
            model.setShareType(item.get(HSOutputParameterNames.SHARE_TYPE).toString());
            combSharesQryModels.add(model);
        }
        return combSharesQryModels;
    }

    /**
     * 投资组合查询
     *
     * @param list
     * @return
     */
    public static List<PortfolioQryModel> populatePortfolioQry(List<Map<String, Object>> list) {
        List<PortfolioQryModel> portfolioQryModels = new ArrayList<>();
        for (Map<String, Object> item : list) {
            PortfolioQryModel model = new PortfolioQryModel();
            // 记录数
            String rowCount = item.get(HSOutputParameterNames.ROWCOUNT).toString();
            if (!StringUtil.isEmpty(rowCount)) {
                model.setRowCount(Long.parseLong(rowCount));
            } else {
                return portfolioQryModels;
            }
            // 总记录数
            String totalCount = item.get(HSOutputParameterNames.TOTAL_COUNT).toString();
            if (!StringUtil.isEmpty(totalCount)) {
                model.setTotalCount(Long.parseLong(totalCount));
            }
            try {
                String beginDateStr = item.get(HSOutputParameterNames.BEGIN_DATE).toString();
                if (Strings.isNullOrEmpty(beginDateStr)) {
                } else {
                    model.setBeginDate(DateUtils.stringToDate4(beginDateStr));
                }

                String endDateStr = item.get(HSOutputParameterNames.END_DATE).toString();

                if (Strings.isNullOrEmpty(endDateStr)) {

                } else {
                    model.setEndDate(DateUtils.stringToDate4(endDateStr));
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
            model.setDiscountRate(BigDecimalUtil.ConvertToBigDecimal(item.get(HSOutputParameterNames.DISCOUNT_RATE).toString()));
//            model.setExplain(item.get(HSOutputParameterNames.EXPLAIN).toString());
            // 2018-1-3 spy fix NPE
            model.setExplain(MapUtils.getStr(item, HSOutputParameterNames.EXPLAIN));
            model.setFundCode(item.get(HSOutputParameterNames.FUND_CODE).toString());
            model.setInvestRate(BigDecimalUtil.ConvertToBigDecimal(item.get(HSOutputParameterNames.INVEST_RATE).toString()));
            model.setPortfolioCode(item.get(HSOutputParameterNames.EXT_COMBCODE).toString());
            model.setProtocolName(item.get(HSOutputParameterNames.PROTOCOL_NAME).toString());
            model.setShareType(item.get(HSOutputParameterNames.SHARE_TYPE).toString());

//            model.setCombState(item.get(HSOutputParameterNames.PORTFOLIO_STATE).toString());
            // 2018-1-3 spy fix NPE
            model.setCombState(MapUtils.getStr(item, HSOutputParameterNames.PORTFOLIO_STATE));
            model.setInnerCombcode(item.get(HSOutputParameterNames.PORTFOLIO_CODE).toString());
            portfolioQryModels.add(model);

        }
        return portfolioQryModels;
    }

    /**
     * populate 非组合基金份额查询
     *
     * @param list
     * @return
     */
    public static List<ShareModel> populateNormalShare(List<Map<String, Object>> list, List<Lookup> lookups) {
        List<ShareModel> shares = new ArrayList<>();
        for (Map<String, Object> item : list) {
            ShareModel model = new ShareModel();
            // 记录数
            String rowCount = item.get(HSOutputParameterNames.ROWCOUNT).toString();
            if (StringUtil.isEmpty(rowCount)) {
                continue;
            }
            model.setAutoBuy(item.get(HSOutputParameterNames.AUTO_BUY).toString());
            model.setAvailableDueShare(BigDecimalUtil
                .ConvertToBigDecimal(item.get(HSOutputParameterNames.AVAILABLE_DUE_SHARE).toString()));
            model.setBankAccount(item.get(HSOutputParameterNames.BANK_ACCOUNT).toString());
            model.setBusinessFrozenAmount(BigDecimalUtil
                .ConvertToBigDecimal(item.get(HSOutputParameterNames.BUSINESS_FROZEN_AMOUNT).toString()));
            model.setCapitalMode(item.get(HSOutputParameterNames.CAPITAL_MODE).toString());
            model.setCurrentShare(
                BigDecimalUtil.ConvertToBigDecimal(item.get(HSOutputParameterNames.CURRENT_SHARE).toString()));
            model.setEnableShares(
                BigDecimalUtil.ConvertToBigDecimal(item.get(HSOutputParameterNames.ENABLE_SHARES).toString()));
            model.setExcetransInTotalQuota(BigDecimalUtil
                .ConvertToBigDecimal(item.get(HSOutputParameterNames.EXCETRANS_IN_TOTAL_QUOTA).toString()));
            model.setExcetransOutTotalQuota(BigDecimalUtil
                .ConvertToBigDecimal(item.get(HSOutputParameterNames.EXCETRANS_OUT_TOTAL_QUOTA).toString()));
            model.setTradeAccount(item.get(HSOutputParameterNames.TRADE_ACCO).toString());
            model.setFrozenShare(
                BigDecimalUtil.ConvertToBigDecimal(item.get(HSOutputParameterNames.FROZEN_SHARE).toString()));
            model.setFundCode(item.get(HSOutputParameterNames.FUND_CODE).toString());
            model.setQuickExceedEnableShare(BigDecimalUtil
                .ConvertToBigDecimal(item.get(HSOutputParameterNames.QUICK_EXCEED_ENABLE_SHARE).toString()));

            model.setShareType(item.get(HSOutputParameterNames.SHARE_TYPE).toString());
            model.setTodayApplyTotalQuota(BigDecimalUtil
                .ConvertToBigDecimal(item.get(HSOutputParameterNames.TODAY_APPLY_TOTAL_QUOTA).toString()));
            model.setTodayExceedTotalQuota(BigDecimalUtil
                .ConvertToBigDecimal(item.get(HSOutputParameterNames.TODAY_EXCEED_TOTAL_QUOTA).toString()));
            model.setCost(BigDecimalUtil.ConvertToBigDecimal(item.get(HSOutputParameterNames.COST).toString()));
            /*
             * model.setTodayIncome(
             * BigDecimalUtil.ConvertToBigDecimal(item.get(
             * HSOutputParameterNames.TODAY_INCOME).toString()));
             */
            model.setTodayTransinTotalQuota(BigDecimalUtil
                .ConvertToBigDecimal(item.get(HSOutputParameterNames.TODAY_TRANSIN_TOTAL_QUOTA).toString()));
            model.setTodayTransoutTotalQuota(BigDecimalUtil
                .ConvertToBigDecimal(item.get(HSOutputParameterNames.TODAY_TRANSOUT_TOTAL_QUOTA).toString()));
            //logger.warn("item未付收益：{}", item.get(HSOutputParameterNames.UNPAID_INCOME).toString());
            model.setUnpaidIncome(
                BigDecimalUtil.ConvertToBigDecimal(item.get(HSOutputParameterNames.UNPAID_INCOME).toString()));
            model.setWorthValue(
                BigDecimalUtil.ConvertToBigDecimal(item.get(HSOutputParameterNames.WORTH_VALUE).toString()));
            model.setTaAccount(item.get(HSOutputParameterNames.TA_ACCO).toString());
            // 累计收益 - add by Shangdu Lin - 20170531
            model.setAccumIncome(BigDecimalUtil.ConvertToBigDecimal(item.get(HSOutputParameterNames.ACCUM_INCOME).toString()));

            String bankNo = item.get(HSOutputParameterNames.BANK_NO).toString().trim();
            if (lookups != null) {
                for (Lookup lookup : lookups) {
                    if (lookup.getRuleValue().equals(bankNo)) {
                        model.setBankCode(lookup.getComponentValue());
                        model.setBankName(lookup.getRuleText());
                        break;
                    }
                }
            }
            // 如果资产为0 && 当前份额为0 && 可用份额为0， 则不显示
            if (model.getCurrentShare().compareTo(new BigDecimal(0)) == 0
                && model.getEnableShares().compareTo(new BigDecimal(0)) == 0) {
                continue;
            }

            shares.add(model);
        }

        return shares;
    }

    /**
     * populate 份额查询
     *
     * @param list
     * @param lookups
     * @param result
     * @return
     */
    public static List<ShareModel> populateShare(List<Map<String, Object>> list, List<Lookup> lookups,
                                                 ShareListResult result) {
        List<ShareModel> shares = new ArrayList<>();
        for (Map<String, Object> item : list) {
            ShareModel model = new ShareModel();
            // 记录数
            String rowCount = item.get(HSOutputParameterNames.ROWCOUNT).toString();
            if (!StringUtil.isEmpty(rowCount)) {
                result.setRowCount(Long.parseLong(rowCount));
            } else {
                return shares;
            }
            // 总记录数
            String totalCount = item.get(HSOutputParameterNames.TOTAL_COUNT).toString();
            if (!StringUtil.isEmpty(totalCount)) {
                result.setTotalCount(Long.parseLong(totalCount));
            }

            model.setAutoBuy(item.get(HSOutputParameterNames.AUTO_BUY).toString());
            model.setAvailableDueShare(BigDecimalUtil
                .ConvertToBigDecimal(item.get(HSOutputParameterNames.AVAILABLE_DUE_SHARE).toString()));
            model.setBankAccount(item.get(HSOutputParameterNames.BANK_ACCOUNT).toString());
            model.setBusinessFrozenAmount(BigDecimalUtil
                .ConvertToBigDecimal(item.get(HSOutputParameterNames.BUSINESS_FROZEN_AMOUNT).toString()));
            model.setCapitalMode(item.get(HSOutputParameterNames.CAPITAL_MODE).toString());
            model.setCurrentShare(
                BigDecimalUtil.ConvertToBigDecimal(item.get(HSOutputParameterNames.CURRENT_SHARE).toString()));
            model.setEnableShares(
                BigDecimalUtil.ConvertToBigDecimal(item.get(HSOutputParameterNames.ENABLE_SHARES).toString()));
            model.setExcetransInTotalQuota(BigDecimalUtil
                .ConvertToBigDecimal(item.get(HSOutputParameterNames.EXCETRANS_IN_TOTAL_QUOTA).toString()));
            model.setExcetransOutTotalQuota(BigDecimalUtil
                .ConvertToBigDecimal(item.get(HSOutputParameterNames.EXCETRANS_OUT_TOTAL_QUOTA).toString()));
            model.setTradeAccount(item.get(HSOutputParameterNames.TRADE_ACCO).toString());
            model.setFrozenShare(
                BigDecimalUtil.ConvertToBigDecimal(item.get(HSOutputParameterNames.FROZEN_SHARE).toString()));
            model.setFundCode(item.get(HSOutputParameterNames.FUND_CODE).toString());
            model.setQuickExceedEnableShare(BigDecimalUtil
                .ConvertToBigDecimal(item.get(HSOutputParameterNames.QUICK_EXCEED_ENABLE_SHARE).toString()));

            model.setShareType(item.get(HSOutputParameterNames.SHARE_TYPE).toString());
            model.setTodayApplyTotalQuota(BigDecimalUtil
                .ConvertToBigDecimal(item.get(HSOutputParameterNames.TODAY_APPLY_TOTAL_QUOTA).toString()));
            model.setTodayExceedTotalQuota(BigDecimalUtil
                .ConvertToBigDecimal(item.get(HSOutputParameterNames.TODAY_EXCEED_TOTAL_QUOTA).toString()));
            /*
             * model.setTodayIncome(
             * BigDecimalUtil.ConvertToBigDecimal(item.get(
             * HSOutputParameterNames.TODAY_INCOME).toString()));
             */
            model.setTodayTransinTotalQuota(BigDecimalUtil
                .ConvertToBigDecimal(item.get(HSOutputParameterNames.TODAY_TRANSIN_TOTAL_QUOTA).toString()));
            model.setTodayTransoutTotalQuota(BigDecimalUtil
                .ConvertToBigDecimal(item.get(HSOutputParameterNames.TODAY_TRANSOUT_TOTAL_QUOTA).toString()));
            //logger.warn("item未付收益：{}", item.get(HSOutputParameterNames.UNPAID_INCOME).toString());
            model.setUnpaidIncome(
                BigDecimalUtil.ConvertToBigDecimal(item.get(HSOutputParameterNames.UNPAID_INCOME).toString()));
            model.setWorthValue(
                BigDecimalUtil.ConvertToBigDecimal(item.get(HSOutputParameterNames.WORTH_VALUE).toString()));
            //成本 zx 2018年1月22日11:09:11
            model.setCost(BigDecimalUtil.ConvertToBigDecimal(item.get(HSOutputParameterNames.COST).toString()));

            // 累计收益 - add by Shangdu Lin - 20170531
            model.setAccumIncome(BigDecimalUtil.ConvertToBigDecimal(item.get(HSOutputParameterNames.ACCUM_INCOME).toString()));
            //logger.info("恒生返回 份额接口 基金编码：{}，累计收益：{}，未付收益：{},成本：{}",model.getFundCode(),model.getAccumIncome(),model.getUnpaidIncome(),model.getCost());
            String bankNo = item.get(HSOutputParameterNames.BANK_NO).toString().trim();
            if (lookups != null) {
                for (Lookup lookup : lookups) {
                    if (lookup.getRuleValue().equals(bankNo)) {
                        model.setBankCode(lookup.getComponentValue());
                        model.setBankName(lookup.getRuleText());
                        break;
                    }
                }
            }
            //logger.debug("银行编号：{}，银行名称：{}",model.getBankCode(),model.getBankName());

            // 如果资产为0 && 当前份额为0 && 可用份额为0， 则不显示
            if (model.getWorthValue().compareTo(new BigDecimal(0)) == 0
                && model.getCurrentShare().compareTo(new BigDecimal(0)) == 0
                && model.getEnableShares().compareTo(new BigDecimal(0)) == 0
                && model.getUnpaidIncome().compareTo(new BigDecimal(0)) == 0) {
                continue;
            }

            shares.add(model);
        }

        return shares;
    }


    /**
     * populate 收益查询
     *
     * @param list
     * @return
     */
    public static List<IncomeModel> populateIncome(List<Map<String, Object>> list) {
        List<IncomeModel> incomes = new ArrayList<>();
        for (Map<String, Object> item : list) {
            IncomeModel model = new IncomeModel();
            // 记录数
            String rowCount = item.get(HSOutputParameterNames.ROWCOUNT).toString();
            if (StringUtil.isEmpty(rowCount)) {
                continue;
            }
            model.setBelongdate(item.get(HSOutputParameterNames.BELONGDATE).toString());
            model.setFundCode(item.get(HSOutputParameterNames.FUND_CODE).toString());
            model.setTodayIncome(BigDecimalUtil.ConvertToBigDecimal(item.get(HSOutputParameterNames.TODAY_INCOME).toString()));
            model.setAccumIncome(BigDecimalUtil.ConvertToBigDecimal(item.get(HSOutputParameterNames.ACCUM_INCOME).toString()));
            model.setAllotNo(item.get(HSOutputParameterNames.ALLOT_NO).toString());
            model.setOccurDate(item.get(HSOutputParameterNames.CCCUR_DATE).toString());
            model.setTradeAccount(item.get(HSOutputParameterNames.TRADE_ACCO).toString());
            incomes.add(model);
        }

        return incomes;
    }

    /**
     * populate TA账户信息
     *
     * @param list
     * @param result
     * @return
     */
    public static List<AccountModel> populateAccount(List<Map<String, Object>> list, BaseListResult result) {

        List<AccountModel> accounts = new ArrayList<>();
        for (Map<String, Object> item : list) {
            AccountModel model = new AccountModel();
            // 记录数
            String rowCount = item.get(HSOutputParameterNames.ROWCOUNT).toString();
            if (!StringUtil.isEmpty(rowCount)) {
                result.setRowCount(Long.parseLong(rowCount));
            } else {
                return accounts;
            }
            // 总记录数
            String totalCount = item.get(HSOutputParameterNames.TOTAL_COUNT).toString();
            if (!StringUtil.isEmpty(totalCount)) {
                result.setTotalCount(Long.parseLong(totalCount));
            }
            model.setClientId(item.get(HSOutputParameterNames.CLIENT_ID).toString());
            model.setMainAccountFlag(item.get(HSOutputParameterNames.MAIN_ACCOUNT_FLAG).toString());
            model.setTradeAccount(item.get(HSOutputParameterNames.TRADE_ACCO).toString());
            // 交易账号状态
            model.setTradeAccountStatus(item.get(HSOutputParameterNames.TRANS_ACCT_STATUS).toString());
            // TA账号状态
            model.setTaAccountStatus(item.get(HSOutputParameterNames.FUND_ACCT_STATUS).toString());
            // TA账号
            model.setTaAccount(item.get(HSOutputParameterNames.TA_ACCO).toString());

            accounts.add(model);
        }

        return accounts;
    }

    /**
     * populate 交易限制信息
     *
     * @param list
     * @return
     */
    public static List<TradeLimitModel> populateTradeLimit(List<Map<String, Object>> list) {
        List<TradeLimitModel> limits = new ArrayList<>();
        for (Map<String, Object> item : list) {
            TradeLimitModel model = new TradeLimitModel();
            // 记录数
            String rowCount = item.get(HSOutputParameterNames.ROWCOUNT).toString();
            if (!StringUtil.isEmpty(rowCount)) {
                model.setRowCount(Long.parseLong(rowCount));
            } else {
                return limits;
            }
            // 总记录数
            String totalCount = item.get(HSOutputParameterNames.TOTAL_COUNT).toString();
            if (!StringUtil.isEmpty(totalCount)) {
                model.setTotalCount(Long.parseLong(totalCount));
            }

            model.setFundBusinCode(item.get(HSOutputParameterNames.FUND_BUSIN_CODE).toString());
            model.setFundCode(item.get(HSOutputParameterNames.FUND_CODE).toString());
            model.setMaxValue(
                BigDecimalUtil.ConvertToBigDecimal(item.get(HSOutputParameterNames.MAX_VALUE).toString()));
            model.setMinValue(
                BigDecimalUtil.ConvertToBigDecimal(item.get(HSOutputParameterNames.MIN_VALUE).toString()));
            model.setSecondMin(
                BigDecimalUtil.ConvertToBigDecimal(item.get(HSOutputParameterNames.SECOND_MIN).toString()));
            model.setShareType(item.get(HSOutputParameterNames.SHARE_TYPE).toString());

            limits.add(model);
        }

        return limits;
    }

    /**
     * populate 交易确认信息
     *
     * @param list
     * @return
     */
    public static List<ConfirmModel> populateConfirm(List<Map<String, Object>> list) {
        List<ConfirmModel> confirms = new ArrayList<>();
        for (Map<String, Object> item : list) {
            ConfirmModel model = new ConfirmModel();
            // 记录数
            String rowCount = item.get(HSOutputParameterNames.ROWCOUNT).toString();
            if (!StringUtil.isEmpty(rowCount)) {
                model.setRowCount(Long.parseLong(rowCount));
            } else {
                return confirms;
            }
            // 总记录数
            String totalCount = item.get(HSOutputParameterNames.TOTAL_COUNT).toString();
            if (!StringUtil.isEmpty(totalCount)) {
                model.setTotalCount(Long.parseLong(totalCount));
            }


            model.setFareSx(BigDecimalUtil.ConvertToBigDecimal(item.get(HSOutputParameterNames.FARE_SX).toString()));
            // 本金
            model.setConfirmBalance(BigDecimalUtil
                .ConvertToBigDecimal(item.get(HSOutputParameterNames.TRADE_CONFIRM_BALANCE).toString()));
            model.setFundBusinCode(item.get(HSOutputParameterNames.FUND_BUSIN_CODE).toString());
            model.setFundCode(item.get(HSOutputParameterNames.FUND_CODE).toString());
            model.setTAConfirmFlag(item.get(HSOutputParameterNames.TACONFIRM_FLAG).toString());
            model.setTradeAcco(item.get(HSOutputParameterNames.TRADE_ACCO).toString());
            // 交易确认份额
            model.setConfirmShares(BigDecimalUtil
                .ConvertToBigDecimal(item.get(HSOutputParameterNames.TRADE_CONFIRM_TYPE).toString()));
            model.setAffirmDate(item.get(HSOutputParameterNames.AFFIRM_DATE).toString());
            model.setOrderDate(item.get(HSOutputParameterNames.ORDER_DATE).toString());
            model.setPortfolioCode(item.get(HSOutputParameterNames.PORTFOLIO_CODE).toString());
            model.setAllotNo(item.get(HSOutputParameterNames.ALLOT_NO).toString());
            model.setTradeConfirmBalance(BigDecimalUtil
                .ConvertToBigDecimal(item.get(HSOutputParameterNames.TRADE_CONFIRM_BALANCE).toString()));
            model.setPortfolioAllotNo(item.get(HSOutputParameterNames.PORTFOLIO_ALLOT_NO).toString());
            confirms.add(model);
        }

        return confirms;
    }

    /**
     * populate 银行卡信息
     *
     * @param list
     * @param lookups
     * @param result
     * @return
     */
    public static List<BankModel> populateBank(List<Map<String, Object>> list, List<Lookup> lookups,
                                               BaseListResult result) {
        List<BankModel> banks = new ArrayList<>();
        for (Map<String, Object> item : list) {

            BankModel model = new BankModel();
            // 记录数
            String rowCount = item.get(HSOutputParameterNames.ROWCOUNT).toString();
            if (!StringUtil.isEmpty(rowCount)) {
                result.setRowCount(Long.parseLong(rowCount));
            } else {
                return banks;
            }
            // 总记录数
            String totalCount = item.get(HSOutputParameterNames.TOTAL_COUNT).toString();
            if (!StringUtil.isEmpty(totalCount)) {
                result.setTotalCount(Long.parseLong(totalCount));
            }

            // 从Lookup获取银行简称和银行名称
            String bankNo = item.get(HSOutputParameterNames.BANK_NO).toString();
            if (lookups != null) {
                for (Lookup lookup : lookups) {
                    if (lookup.getRuleValue().equals(bankNo)) {
                        model.setBankCode(lookup.getComponentValue());
                        model.setBankName(lookup.getRuleText());
                        break;
                    }
                }
            }
            model.setUserBankNo(item.get(HSOutputParameterNames.BANK_ACCOUNT).toString());
            model.setCapitalMode(item.get(HSOutputParameterNames.CAPITAL_MODE).toString());
            // 交易账号
            model.setTradeAccount(item.get(HSOutputParameterNames.TRADE_ACCO).toString());

            banks.add(model);
        }

        return banks;
    }

    /**
     * populate 份额类别
     *
     * @param list
     * @return
     */
    public static List<ShareTypeModel> populateShareType(List<Map<String, Object>> list) {
        List<ShareTypeModel> shareTypes = new ArrayList<>();
        for (Map<String, Object> item : list) {
            ShareTypeModel model = new ShareTypeModel();

            // 记录数
            String rowCount = item.get(HSOutputParameterNames.ROWCOUNT).toString();
            if (!StringUtil.isEmpty(rowCount)) {
                model.setRowCount(Long.parseLong(rowCount));
            } else {
                return shareTypes;
            }
            // 总记录数
            String totalCount = item.get(HSOutputParameterNames.TOTAL_COUNT).toString();
            if (!StringUtil.isEmpty(totalCount)) {
                model.setTotalCount(Long.parseLong(totalCount));
            }

            model.setFundCode(item.get(HSOutputParameterNames.FUND_CODE).toString());
            model.setFundName(item.get(HSOutputParameterNames.FUND_NAME).toString());
            model.setFundStatus(item.get(HSOutputParameterNames.FUND_STATUS).toString());
            model.setFundType(item.get(HSOutputParameterNames.OFUND_TYPE).toString());
            model.setShareType(item.get(HSOutputParameterNames.SHARE_TYPE).toString());

            shareTypes.add(model);
        }

        return shareTypes;
    }

    /**
     * populate 交易申请
     *
     * @param list
     * @param result
     * @param tradeLookups
     * @param bankLookups
     * @return
     */
    public static List<ApplyModel> populateApply(List<Map<String, Object>> list, ApplyListResult result,
                                                 List<Lookup> tradeLookups, List<Lookup> bankLookups) {
        List<ApplyModel> applys = new ArrayList<>();
        for (Map<String, Object> item : list) {
            ApplyModel model = new ApplyModel();
            // 记录数
            String rowCount = item.get(HSOutputParameterNames.ROWCOUNT).toString();
            if (!StringUtil.isEmpty(rowCount)) {
                result.setRowCount(Long.parseLong(rowCount));
            } else {
                return applys;
            }
            // 总记录数
            String totalCount = item.get(HSOutputParameterNames.TOTAL_COUNT).toString();
            if (!StringUtil.isEmpty(totalCount)) {
                result.setTotalCount(Long.parseLong(totalCount));
            }

            // 过滤掉撤单申请交易

            model.setFundBusinCode(item.get(HSOutputParameterNames.FUND_BUSIN_CODE).toString());
            if (model.getFundBusinCode().equals(GlobalConstant.FUND_BUSIN_CODE_APPLY_UNDO)) {
                continue;
            }

            model.setAllotNo(item.get(HSOutputParameterNames.ALLOT_NO).toString());
            model.setBalance(BigDecimalUtil.ConvertToBigDecimal(item.get(HSOutputParameterNames.BALANCE).toString()));
            model.setFundCode(item.get(HSOutputParameterNames.FUND_CODE).toString());
            model.setOrderDate(item.get(HSOutputParameterNames.CURR_DATE).toString());
            model.setOrderTime(item.get(HSOutputParameterNames.CURR_TIME).toString());
            model.setDeductStatus(item.get(HSOutputParameterNames.DEDUCT_STATUS).toString());
            model.setTAConfirmFlag(item.get(HSOutputParameterNames.TACONFIRM_FLAG).toString());
            // model.setFundBusinCode(item.get(HSOutputParameterNames.FUND_BUSIN_CODE).toString());
            model.setTradeAcco(item.get(HSOutputParameterNames.TRADE_ACCO).toString());
            model.setSendFlag(item.get(HSOutputParameterNames.SEND_FLAGS).toString());
            model.setApplyDate(item.get(HSOutputParameterNames.APPLY_DATE).toString());
            model.setShares(BigDecimalUtil.ConvertToBigDecimal(item.get(HSOutputParameterNames.SHARES).toString()));
            // 恒生代码
            model.setBankHSCode(item.get(HSOutputParameterNames.BANK_NO).toString());
            model.setPortfolioCode(item.get(HSOutputParameterNames.PORTFOLIO_CODE).toString());
            //业务辅助代码  zx 2018年1月22日11:32:06
            model.setBusinAssCode(item.get(HSOutputParameterNames.BUSIN_ASS_CODE).toString());

            model.setReceivableAccount(item.get(HSOutputParameterNames.RECEIVABLE_ACCOUNT).toString());

            // 设置交易业务名称
            if (tradeLookups != null) {
                for (Lookup lookup : tradeLookups) {
                    if (lookup.getRuleValue().equals(model.getFundBusinCode())) {
                        model.setFundBusinName(lookup.getRuleText());
                        break;
                    }
                }
            }

            // 设置银行名称
            if (bankLookups != null) {
                for (Lookup lookup : bankLookups) {
                    if (lookup.getRuleValue().equals(model.getBankHSCode())) {
                        model.setBankName(lookup.getRuleText());
                        break;
                    }
                }
            }

            applys.add(model);
        }

        return applys;
    }

    /**
     * populate 交易申请  不过滤撤单
     *
     * @param list
     * @param result
     * @param tradeLookups
     * @param bankLookups
     * @return
     */
    public static List<ApplyModel> populateApplyForUndo(List<Map<String, Object>> list, ApplyListResult result,
                                                        List<Lookup> tradeLookups, List<Lookup> bankLookups) {
        List<ApplyModel> applys = new ArrayList<>();
        for (Map<String, Object> item : list) {
            ApplyModel model = new ApplyModel();
            // 记录数
            String rowCount = item.get(HSOutputParameterNames.ROWCOUNT).toString();
            if (!StringUtil.isEmpty(rowCount)) {
                result.setRowCount(Long.parseLong(rowCount));
            } else {
                return applys;
            }
            // 总记录数
            String totalCount = item.get(HSOutputParameterNames.TOTAL_COUNT).toString();
            if (!StringUtil.isEmpty(totalCount)) {
                result.setTotalCount(Long.parseLong(totalCount));
            }

            // 过滤掉撤单申请交易

            model.setFundBusinCode(item.get(HSOutputParameterNames.FUND_BUSIN_CODE).toString());

            model.setAllotNo(item.get(HSOutputParameterNames.ALLOT_NO).toString());
            model.setBalance(BigDecimalUtil.ConvertToBigDecimal(item.get(HSOutputParameterNames.BALANCE).toString()));
            model.setFundCode(item.get(HSOutputParameterNames.FUND_CODE).toString());
            model.setOrderDate(item.get(HSOutputParameterNames.CURR_DATE).toString());
            model.setOrderTime(item.get(HSOutputParameterNames.CURR_TIME).toString());
            model.setDeductStatus(item.get(HSOutputParameterNames.DEDUCT_STATUS).toString());
            model.setTAConfirmFlag(item.get(HSOutputParameterNames.TACONFIRM_FLAG).toString());
            // model.setFundBusinCode(item.get(HSOutputParameterNames.FUND_BUSIN_CODE).toString());
            model.setTradeAcco(item.get(HSOutputParameterNames.TRADE_ACCO).toString());
            model.setSendFlag(item.get(HSOutputParameterNames.SEND_FLAGS).toString());
            model.setApplyDate(item.get(HSOutputParameterNames.APPLY_DATE).toString());
            model.setShares(BigDecimalUtil.ConvertToBigDecimal(item.get(HSOutputParameterNames.SHARES).toString()));
            // 恒生代码
            model.setBankHSCode(item.get(HSOutputParameterNames.BANK_NO).toString());
            model.setPortfolioCode(item.get(HSOutputParameterNames.PORTFOLIO_CODE).toString());
            //业务辅助代码  zx 2018年1月22日11:32:06
            model.setBusinAssCode(item.get(HSOutputParameterNames.BUSIN_ASS_CODE).toString());

            model.setReceivableAccount(item.get(HSOutputParameterNames.RECEIVABLE_ACCOUNT).toString());

            // 设置交易业务名称
            if (tradeLookups != null) {
                for (Lookup lookup : tradeLookups) {
                    if (lookup.getRuleValue().equals(model.getFundBusinCode())) {
                        model.setFundBusinName(lookup.getRuleText());
                        break;
                    }
                }
            }

            // 设置银行名称
            if (bankLookups != null) {
                for (Lookup lookup : bankLookups) {
                    if (lookup.getRuleValue().equals(model.getBankHSCode())) {
                        model.setBankName(lookup.getRuleText());
                        break;
                    }
                }
            }

            applys.add(model);
        }

        return applys;
    }

    /**
     * 交易申请2.0   给组合 用
     *
     * @param list
     * @param result
     * @param tradeLookups
     * @param bankLookups
     * @param isOrg
     * @return
     */
    public static List<ApplyModel> populateApply2(List<Map<String, Object>> list, PortfolioApplyListResult result,
                                                  List<Lookup> tradeLookups, List<Lookup> bankLookups, Boolean isOrg) {
        List<ApplyModel> applys = new ArrayList<>();
        for (Map<String, Object> item : list) {
            ApplyModel model = new ApplyModel();
            // 记录数
            String rowCount = item.get(HSOutputParameterNames.ROWCOUNT).toString();
            if (!StringUtil.isEmpty(rowCount)) {
                result.setRowCount(Long.parseLong(rowCount));
            } else {
                return applys;
            }
            // 总记录数
            String totalCount = item.get(HSOutputParameterNames.TOTAL_COUNT).toString();
            if (!StringUtil.isEmpty(totalCount)) {
                result.setTotalCount(Long.parseLong(totalCount));
            }

            // 过滤掉撤单申请交易
            model.setFundBusinCode(item.get(HSOutputParameterNames.FUND_BUSIN_CODE).toString());
            if (model.getFundBusinCode().equals(GlobalConstant.FUND_BUSIN_CODE_APPLY_UNDO)) {
                continue;
            }

            model.setAllotNo(item.get(HSOutputParameterNames.ALLOT_NO).toString());
            model.setBalance(BigDecimalUtil.ConvertToBigDecimal(item.get(HSOutputParameterNames.BALANCE).toString()));
            model.setFundCode(item.get(HSOutputParameterNames.FUND_CODE).toString());

            model.setOrderDate(item.get(HSOutputParameterNames.CURR_DATE).toString());
            model.setOrderTime(item.get(HSOutputParameterNames.CURR_TIME).toString());
            model.setDeductStatus(item.get(HSOutputParameterNames.DEDUCT_STATUS).toString());
            model.setTAConfirmFlag(item.get(HSOutputParameterNames.TACONFIRM_FLAG).toString());
            // model.setFundBusinCode(item.get(HSOutputParameterNames.FUND_BUSIN_CODE).toString());
            model.setTradeAcco(item.get(HSOutputParameterNames.TRADE_ACCO).toString());
            model.setSendFlag(item.get(HSOutputParameterNames.SEND_FLAGS).toString());
            model.setApplyDate(item.get(HSOutputParameterNames.APPLY_DATE).toString());
            model.setShares(BigDecimalUtil.ConvertToBigDecimal(item.get(HSOutputParameterNames.SHARES).toString()));
            // 恒生代码
            model.setBankHSCode(item.get(HSOutputParameterNames.BANK_NO).toString());

            model.setPortfolioAllotNo(item.get(HSOutputParameterNames.PORTFOLIO_ALLOT_NO).toString());
            model.setPortfolioCode(item.get(HSOutputParameterNames.PORTFOLIO_CODE).toString());
            model.setProtocolName(item.get(HSOutputParameterNames.PROTOCOL_NAME).toString());
            model.setBusinAssCode(item.get(HSOutputParameterNames.BUSIN_ASS_CODE).toString());

            //原申请编号
            model.setOriginalAppno(item.get(HSOutputParameterNames.ORIGINAL_APPNO).toString());
            // 设置交易业务名称
            if (tradeLookups != null) {
                for (Lookup lookup : tradeLookups) {
                    if (lookup.getRuleValue().equals(model.getFundBusinCode())) {
                        model.setFundBusinName(lookup.getRuleText());
                        break;
                    }
                }
            }

            // 设置银行名称
            if (bankLookups != null) {
                for (Lookup lookup : bankLookups) {
                    if (lookup.getRuleValue().equals(model.getBankHSCode())) {
                        model.setBankName(lookup.getRuleText());
                        break;
                    }
                }
            }
            model.setIsOrg(isOrg);
            applys.add(model);
        }

        return applys;
    }


    /**
     * 交易申请2.0
     *
     * @param list
     * @param result
     * @param tradeLookups
     * @param bankLookups
     * @param isOrg
     * @return
     */
    public static List<ApplyModel> populateApply2(List<Map<String, Object>> list, ApplyListResult result,
                                                  List<Lookup> tradeLookups, List<Lookup> bankLookups, Boolean isOrg) {
        List<ApplyModel> applys = new ArrayList<>();
        for (Map<String, Object> item : list) {
            ApplyModel model = new ApplyModel();
            // 记录数
            String rowCount = item.get(HSOutputParameterNames.ROWCOUNT).toString();
            if (!StringUtil.isEmpty(rowCount)) {
                result.setRowCount(Long.parseLong(rowCount));
            } else {
                return applys;
            }
            // 总记录数
            String totalCount = item.get(HSOutputParameterNames.TOTAL_COUNT).toString();
            if (!StringUtil.isEmpty(totalCount)) {
                result.setTotalCount(Long.parseLong(totalCount));
            }

            // 过滤掉撤单申请交易
            //再过滤掉设置分红方式的交易记录 zx  2018年2月5日16:03:15
            model.setFundBusinCode(item.get(HSOutputParameterNames.FUND_BUSIN_CODE).toString());
            if (model.getFundBusinCode().equals(GlobalConstant.FUND_BUSIN_CODE_APPLY_UNDO) || model.getFundBusinCode().equals(GlobalConstant.FUND_BUSIN_CODE_APPLY_BONUS)) {
                continue;
            }

            model.setCapitalMode(item.get(HSOutputParameterNames.CAPITAL_MODE).toString());
            model.setAllotNo(item.get(HSOutputParameterNames.ALLOT_NO).toString());
            model.setBalance(BigDecimalUtil.ConvertToBigDecimal(item.get(HSOutputParameterNames.BALANCE).toString()));
            model.setFundCode(item.get(HSOutputParameterNames.FUND_CODE).toString());
            model.setOrderDate(item.get(HSOutputParameterNames.CURR_DATE).toString());
            model.setOrderTime(item.get(HSOutputParameterNames.CURR_TIME).toString());
            model.setDeductStatus(item.get(HSOutputParameterNames.DEDUCT_STATUS).toString());
            model.setTAConfirmFlag(item.get(HSOutputParameterNames.TACONFIRM_FLAG).toString());
            // model.setFundBusinCode(item.get(HSOutputParameterNames.FUND_BUSIN_CODE).toString());
            model.setTradeAcco(item.get(HSOutputParameterNames.TRADE_ACCO).toString());
            model.setSendFlag(item.get(HSOutputParameterNames.SEND_FLAGS).toString());
            model.setApplyDate(item.get(HSOutputParameterNames.APPLY_DATE).toString());
            model.setShares(BigDecimalUtil.ConvertToBigDecimal(item.get(HSOutputParameterNames.SHARES).toString()));
            // 恒生代码
            model.setBankHSCode(item.get(HSOutputParameterNames.BANK_NO).toString());
            model.setTargetFundCode(item.get(HSOutputParameterNames.TARGET_FUND_CODE).toString());
            model.setPortfolioAllotNo(item.get(HSOutputParameterNames.PORTFOLIO_ALLOT_NO).toString());
            model.setPortfolioCode(item.get(HSOutputParameterNames.PORTFOLIO_CODE).toString());
            model.setBusinAssCode(item.get(HSOutputParameterNames.BUSIN_ASS_CODE).toString());
            model.setOriginalAppno(item.get(HSOutputParameterNames.ORIGINAL_APPNO).toString());
            model.setBankAccount(item.get(HSOutputParameterNames.RECEIVABLE_ACCOUNT).toString());
            // 设置交易业务名称
            if (tradeLookups != null) {
                for (Lookup lookup : tradeLookups) {
                    if (lookup.getRuleValue().equals(model.getFundBusinCode())) {
                        model.setFundBusinName(lookup.getRuleText());
                        break;
                    }
                }
            }

            // 设置银行名称
            if (bankLookups != null) {
                for (Lookup lookup : bankLookups) {
                    if (lookup.getRuleValue().equals(model.getBankHSCode())) {
                        model.setBankName(lookup.getRuleText());
                        break;
                    }
                }
            }
            model.setIsOrg(isOrg);
            applys.add(model);
        }

        return applys;
    }

    /**
     * 组合交易申请2.0
     *
     * @param list
     * @param result
     * @param tradeLookups
     * @param bankLookups
     * @param isOrg
     * @return
     */
    public static List<PortfolioApplyModel> populatePortfolioApply(List<Map<String, Object>> list, PortfolioApplyListResult result,
                                                                   List<Lookup> tradeLookups, List<Lookup> bankLookups, Boolean isOrg) {
        List<PortfolioApplyModel> applys = new ArrayList<>();
        for (Map<String, Object> item : list) {
            PortfolioApplyModel model = new PortfolioApplyModel();
            // 记录数
            String rowCount = item.get(HSOutputParameterNames.ROWCOUNT).toString();
            if (!StringUtil.isEmpty(rowCount)) {
                result.setRowCount(Long.parseLong(rowCount));
            } else {
                return applys;
            }
            // 总记录数
            String totalCount = item.get(HSOutputParameterNames.TOTAL_COUNT).toString();
            if (!StringUtil.isEmpty(totalCount)) {
                result.setTotalCount(Long.parseLong(totalCount));
            }

            // 过滤掉撤单申请交易
            model.setFundBusinCode(item.get(HSOutputParameterNames.FUND_BUSIN_CODE).toString());
            if (model.getFundBusinCode().equals(GlobalConstant.FUND_BUSIN_CODE_APPLY_UNDO)) {
                continue;
            }

            model.setAllotNo(item.get(HSOutputParameterNames.ALLOT_NO).toString());
            model.setBalance(BigDecimalUtil.ConvertToBigDecimal(item.get(HSOutputParameterNames.BALANCE).toString()));
            model.setFundCode(item.get(HSOutputParameterNames.FUND_CODE).toString());
            model.setOrderDate(item.get(HSOutputParameterNames.CURR_DATE).toString());
            model.setOrderTime(item.get(HSOutputParameterNames.CURR_TIME).toString());
            model.setDeductStatus(item.get(HSOutputParameterNames.DEDUCT_STATUS).toString());
            model.setTAConfirmFlag(item.get(HSOutputParameterNames.TACONFIRM_FLAG).toString());
            model.setReceivableAccount(item.get(HSOutputParameterNames.RECEIVABLE_ACCOUNT).toString());
            // model.setFundBusinCode(item.get(HSOutputParameterNames.FUND_BUSIN_CODE).toString());
            model.setTradeAcco(item.get(HSOutputParameterNames.TRADE_ACCO).toString());
            model.setSendFlag(item.get(HSOutputParameterNames.SEND_FLAGS).toString());
            model.setApplyDate(item.get(HSOutputParameterNames.APPLY_DATE).toString());
            model.setShares(BigDecimalUtil.ConvertToBigDecimal(item.get(HSOutputParameterNames.SHARES).toString()));
            logger.debug("orderDate:{},applyDate:{},fundCode:{},portfolioCode:{}", model.getOrderDateReal(), model.getApplyDateReal(), model.getFundCode(), model.getPortfolioCode());
            // 恒生代码
            model.setBankHSCode(item.get(HSOutputParameterNames.BANK_NO).toString());

            model.setPortfolioAllotNo(item.get(HSOutputParameterNames.PORTFOLIO_ALLOT_NO).toString());
            model.setPortfolioCode(item.get(HSOutputParameterNames.PORTFOLIO_CODE).toString());
            model.setExtPortfolioCode(item.get(HSOutputParameterNames.EXT_COMBCODE).toString());
            model.setProtocolName(item.get(HSOutputParameterNames.PROTOCOL_NAME).toString());
            model.setBusinAssCode(item.get(HSOutputParameterNames.BUSIN_ASS_CODE).toString());
            // 设置交易业务名称
            if (tradeLookups != null) {
                for (Lookup lookup : tradeLookups) {
                    if (lookup.getRuleValue().equals(model.getFundBusinCode())) {
                        model.setFundBusinName(lookup.getRuleText());
                        break;
                    }
                }
            }

            // 设置银行名称
            if (bankLookups != null) {
                for (Lookup lookup : bankLookups) {
                    if (lookup.getRuleValue().equals(model.getBankHSCode())) {
                        model.setBankName(lookup.getRuleText());
                        break;
                    }
                }
            }
            model.setIsOrg(isOrg);


            applys.add(model);
        }

        return applys;
    }

//    public static void getStatusString(PortfolioApplyModel portfolioApplyModel) {
//        if (!portfolioApplyModel.getIsOrg()){
//            if (portfolioApplyModel.getFundBusinCode().equals(GlobalConstant.FUND_BUSIN_CODE_APPLY_BUY)){
//                if (portfolioApplyModel.getTAConfirmFlag().equals(GlobalConstant.TACONFIRM_FLAG_UNCONFIRM)){
//                    if (portfolioApplyModel.getDeductStatus().equals(GlobalConstant.DEDUCT_STATUS_SENT)){
//                        portfolioApplyModel.setStatus(GlobalConstant.PERSON_BUY_UNCONFIRM_CHARGED);
//                    }
//                    if (portfolioApplyModel.getDeductStatus().equals(GlobalConstant.DEDUCT_STATUS_VALID)){
//                        portfolioApplyModel.setStatus(GlobalConstant.PERSON_BUY_UNCONFIRM_CHARGEDSUC);
//                    }
//                    if (portfolioApplyModel.getDeductStatus().equals(GlobalConstant.DEDUCT_STATUS_INVALID)){
//                        portfolioApplyModel.setStatus(GlobalConstant.PERSON_BUY_UNCONFIRM_CHARGEDFAIL);
//                    }
//                }
//                if (portfolioApplyModel.getTAConfirmFlag().equals(GlobalConstant.TACONFIRM_FLAG_FAIL)){
//                    if (portfolioApplyModel.getDeductStatus().equals(GlobalConstant.DEDUCT_STATUS_VALID)){
//                        portfolioApplyModel.setStatus(GlobalConstant.PERSON_BUY_CONFIRMFAIL_CHARGEDSUC);
//                    }
//                }
//                if (portfolioApplyModel.getTAConfirmFlag().equals(GlobalConstant.TACONFIRM_FLAG_CONFIRMED)){
//                    if (portfolioApplyModel.getDeductStatus().equals(GlobalConstant.DEDUCT_STATUS_VALID)){
//                        portfolioApplyModel.setStatus(GlobalConstant.PERSON_BUY_CONFIRMSUC_CHARGEDSUC);
//                    }
//                }
//                if (portfolioApplyModel.getTAConfirmFlag().equals(GlobalConstant.TACONFIRM_FLAG_UNDO)){
//                    portfolioApplyModel.setStatus(GlobalConstant.PERSON_BUY_BACK);
//                }
//            }
//            if (portfolioApplyModel.getFundBusinCode().equals(GlobalConstant.FUND_BUSIN_CODE_APPLY_SELL)){
//                if (portfolioApplyModel.getTAConfirmFlag().equals(GlobalConstant.TACONFIRM_FLAG_UNCONFIRM)){
//                    portfolioApplyModel.setStatus(GlobalConstant.PERSON_SELL_UNCONFIRM);
//                }
//                if (portfolioApplyModel.getTAConfirmFlag().equals(GlobalConstant.TACONFIRM_FLAG_CONFIRMED)){
//                    portfolioApplyModel.setStatus(GlobalConstant.PERSON_SELL_CONFIRMSUC);
//                }
//                if (portfolioApplyModel.getTAConfirmFlag().equals(GlobalConstant.TACONFIRM_FLAG_UNDO)){
//                    portfolioApplyModel.setStatus(GlobalConstant.PERSON_SELL_BACK);
//                }
//            }
//        } else {
//            if (portfolioApplyModel.getFundBusinCode().equals(GlobalConstant.FUND_BUSIN_CODE_APPLY_BUY)){
//                if (portfolioApplyModel.getTAConfirmFlag().equals(GlobalConstant.TACONFIRM_FLAG_UNCONFIRM)){
//                    if (portfolioApplyModel.getDeductStatus().equals(GlobalConstant.DEDUCT_STATUS_UNCHECK)){
//                        portfolioApplyModel.setStatus(GlobalConstant.MECHANISM_BUY_UNCONFIRM_NOCHARGED);
//                    }
//                    if (portfolioApplyModel.getDeductStatus().equals(GlobalConstant.DEDUCT_STATUS_VALID)){
//                        portfolioApplyModel.setStatus(GlobalConstant.MECHANISM_BUY_UNCONFIRM_CHARGEDSUC);
//                    }
//                    if (portfolioApplyModel.getDeductStatus().equals(GlobalConstant.DEDUCT_STATUS_INVALID)){
//                        portfolioApplyModel.setStatus(GlobalConstant.MECHANISM_BUY_UNCONFIRM_CHARGEDFAIL);
//                    }
//                }
//                if (portfolioApplyModel.getTAConfirmFlag().equals(GlobalConstant.TACONFIRM_FLAG_FAIL)){
//                    if (portfolioApplyModel.getDeductStatus().equals(GlobalConstant.DEDUCT_STATUS_VALID)){
//                        portfolioApplyModel.setStatus(GlobalConstant.MECHANISM_BUY_CONFIRMFAIL_CHARGEDSUC);
//                    }
//                }
//                if (portfolioApplyModel.getTAConfirmFlag().equals(GlobalConstant.TACONFIRM_FLAG_CONFIRMED)){
//                    if (portfolioApplyModel.getDeductStatus().equals(GlobalConstant.DEDUCT_STATUS_VALID)){
//                        portfolioApplyModel.setStatus(GlobalConstant.MECHANISM_BUY_CONFIRMSUC_CHARGEDSUC);
//                    }
//                }
//                if (portfolioApplyModel.getTAConfirmFlag().equals(GlobalConstant.TACONFIRM_FLAG_UNDO)){
//                    portfolioApplyModel.setStatus(GlobalConstant.MECHANISM_BUY_BACK);
//                }
//            }
//            if (portfolioApplyModel.getFundBusinCode().equals(GlobalConstant.FUND_BUSIN_CODE_APPLY_SELL)){
//                if (portfolioApplyModel.getTAConfirmFlag().equals(GlobalConstant.TACONFIRM_FLAG_UNCONFIRM)){
//                    portfolioApplyModel.setStatus(GlobalConstant.MECHANISM_SELL_UNCONFIRM);
//                }
//                if (portfolioApplyModel.getTAConfirmFlag().equals(GlobalConstant.TACONFIRM_FLAG_CONFIRMED)){
//                    portfolioApplyModel.setStatus(GlobalConstant.MECHANISM_SELL_CONFIRMSUC);
//                }
//                if (portfolioApplyModel.getTAConfirmFlag().equals(GlobalConstant.TACONFIRM_FLAG_UNDO)){
//                    portfolioApplyModel.setStatus(GlobalConstant.MECHANISM_SELL_BACK);
//                }
//            }
//        }
//    }

    /**
     * populate 基金查询
     *
     * @param list
     * @param result
     * @return
     */
    public static List<FundModel> populateFund(List<Map<String, Object>> list, FundListResult result) {
        List<FundModel> funds = new ArrayList<>();
        for (Map<String, Object> item : list) {
            FundModel model = new FundModel();
            // 记录数
            String rowCount = item.get(HSOutputParameterNames.ROWCOUNT).toString();
            if (!StringUtil.isEmpty(rowCount)) {
                result.setRowCount(Long.parseLong(rowCount));
            } else {
                return funds;
            }
            // 总记录数
            String totalCount = item.get(HSOutputParameterNames.TOTAL_COUNT).toString();
            if (!StringUtil.isEmpty(totalCount)) {
                result.setTotalCount(Long.parseLong(totalCount));
            }
            model.setFundCode(item.get(HSOutputParameterNames.FUND_CODE).toString());
            model.setFundName(item.get(HSOutputParameterNames.FUND_NAME).toString());
            model.setFundStatus(item.get(HSOutputParameterNames.FUND_STATUS).toString());
            model.setTANo(item.get(HSOutputParameterNames.TA_NO).toString());
            model.setFundType(item.get(HSOutputParameterNames.OFUND_TYPE).toString());

            funds.add(model);
        }

        return funds;
    }


    /**
     * 判断是否是T0基金
     *
     * @param lookups
     * @param fundCode
     * @return
     */
    public static boolean isT0Fund(List<Lookup> lookups, String fundCode) {
        if (CollectionUtils.isEmpty(lookups)) {
            return false;
        }
        for (Lookup lookup : lookups) {
            if (lookup.getRuleValue().equals(fundCode)) {
                return true;
            }
        }

        return false;
    }


    /**
     * populate分红明细
     *
     * @param list
     * @param result
     * @return
     */
    public static List<DividendModel> populateDividend(List<Map<String, Object>> list, BaseListResult result) {
        List<DividendModel> dividends = new ArrayList<>();
        for (Map<String, Object> item : list) {
            DividendModel model = new DividendModel();
            // 记录数
            String rowCount = item.get(HSOutputParameterNames.ROWCOUNT).toString();
            if (!StringUtil.isEmpty(rowCount)) {
                result.setRowCount(Long.parseLong(rowCount));
            } else {
                return dividends;
            }
            // 总记录数
            String totalCount = item.get(HSOutputParameterNames.TOTAL_COUNT).toString();
            if (!StringUtil.isEmpty(totalCount)) {
                result.setTotalCount(Long.parseLong(totalCount));
            }


            // 每股分红金额
            model.setUnitBala(BigDecimalUtil.ConvertToBigDecimal(item.get(HSOutputParameterNames.UNIT_BALA).toString()));
            // 每股分红份额
            model.setUnitShare(BigDecimalUtil.ConvertToBigDecimal(item.get(HSOutputParameterNames.UNIT_SHARE).toString()));
            // 净值
            model.setNetValue(BigDecimalUtil.ConvertToBigDecimal(item.get(HSOutputParameterNames.NET_VALUE).toString()));
            // 冻结金额
            model.setFrozenBala(BigDecimalUtil.ConvertToBigDecimal(item.get(HSOutputParameterNames.FROZEN_BALA).toString()));
            // 冻结份额
            model.setFrozenShares(BigDecimalUtil.ConvertToBigDecimal(item.get(HSOutputParameterNames.FROZEN_SHARES).toString()));
            // 交易账号
            model.setTradeAccount(item.get(HSOutputParameterNames.TRADE_ACCO).toString());
            // TA账号
            model.setTaAccount(item.get(HSOutputParameterNames.TA_ACCO).toString());
            // 基金代码
            model.setFundCode(item.get(HSOutputParameterNames.FUND_CODE).toString());
            // 红利总金额
            model.setTotalDividendBalance(BigDecimalUtil.ConvertToBigDecimal(item.get(HSOutputParameterNames
                .DIVIDEND_TOTALBALA).toString()));
            //红利实发金额
            model.setDividendBalance(BigDecimalUtil.ConvertToBigDecimal(item.get(HSOutputParameterNames.DIVIDEND_BALA).toString()));
            //权益登记日
            model.setEquityRegDate(item.get(HSOutputParameterNames.EQUITY_REG_DATE).toString());
            //分红日
            model.setDividendDate(item.get(HSOutputParameterNames.DIVIDEND_DATE).toString());
            //银行编号
            model.setBangNo(item.get(HSOutputParameterNames.BANK_NO).toString());
            //银行卡号
            model.setBankAccount(item.get(HSOutputParameterNames.BANK_ACCOUNT).toString());
            //确认状态
            model.setStatus(GlobalConstant.DIVIDEND_CONFIRM);
            //确认日期
            model.setAffirmDate(item.get(HSOutputParameterNames.AFFIRM_DATE).toString());
            //分红方式
            model.setAutoBuy(item.get(HSOutputParameterNames.AUTO_BUY).toString());
            //确认份额
            model.setDividendShare(BigDecimalUtil.ConvertToBigDecimal(item.get(HSOutputParameterNames.DIVIDEND_SHARE).toString()));
            model.setTaSerialId(item.get(HSOutputParameterNames.TA_SERIAL_ID).toString());
            dividends.add(model);
        }

        return dividends;
    }

    /**
     * populate客户信息
     *
     * @param map
     * @return
     */
    public static ClientInfoModel populateClientInfo(Map<String, Object> map) {
        ClientInfoModel model = new ClientInfoModel();

        if (map != null) {
            model.setClientFullName(map.get(HSOutputParameterNames.CLIENT_FULL_NAME).toString());
            model.setClientName(map.get(HSOutputParameterNames.CLIENT_NAME).toString());
            model.setIdNo(map.get(HSOutputParameterNames.ID_NO).toString());
            model.setIdKind(map.get(HSOutputParameterNames.ID_KIND_GB).toString());
            model.setMobile(map.get(HSOutputParameterNames.MOBILE_TEL).toString());
            if (EqualsUtil.equals(model.getIdKind(), HsConst.ID_KIND_GB_ID_CARD)) {
                model.setBirthday(IdCardUtil.getBirthday(model.getIdNo()));
            }


            //model.setProfessionalFlag(map.get(HSOutputParameterNames.PUB_PROF_FLAG).toString());
            // 2018-1-3 spy fix NPE
            model.setProfessionalFlag(MapUtils.getStr(map, HSOutputParameterNames.PUB_PROF_FLAG));
            model.setAddress(map.get(HSOutputParameterNames.ADDRESS).toString());
            model.setTradeAccountName(map.get(HSOutputParameterNames.TRADE_ACCOUNT_NAME).toString());

//            model.setQualifiedFlag(map.get(HSOutputParameterNames.PUB_HG_FLAG).toString());
            model.setQualifiedFlag(MapUtils.getStr(map, HSOutputParameterNames.PUB_HG_FLAG));

            //String risk = map.get(HSOutputParameterNames.INVEST_RISK_TOLERANCE).toString();
            String risk = MapUtils.getStr(map, HSOutputParameterNames.INVEST_RISK_TOLERANCE);
            if (StringUtil.isNotEmpty(risk) && risk.trim().length() != 0) {
                model.setInvestRiskTolerance(Integer.parseInt(risk));
            }
        }
        return model;
    }

    /**
     * populate警示模板内容
     *
     * @param list
     * @param result
     * @return
     */
    public static List<WarningModel> populateWarnings(List<Map<String, Object>> list, BaseListResult result) {
        List<WarningModel> warnings = new ArrayList<>();
        for (Map<String, Object> item : list) {
            WarningModel model = new WarningModel();
            // 记录数
            String rowCount = item.get(HSOutputParameterNames.ROWCOUNT).toString();
            if (!StringUtil.isEmpty(rowCount)) {
                result.setRowCount(Long.parseLong(rowCount));
            } else {
                return warnings;
            }
            // 总记录数
            String totalCount = item.get(HSOutputParameterNames.TOTAL_COUNT).toString();
            if (!StringUtil.isEmpty(totalCount)) {
                result.setTotalCount(Long.parseLong(totalCount));
            }

            model.setWarningNo(item.get(HSOutputParameterNames.WARNING_NO).toString());
            model.setWarningType(item.get(HSOutputParameterNames.WARNING_TYPE).toString());
            model.setWarningContent(item.get(HSOutputParameterNames.WARNING_CONTENT).toString());

            warnings.add(model);
        }

        return warnings;
    }

    /**
     * populate待办事项
     *
     * @param list
     * @param result
     * @return
     */
    public static List<ToDoModel> populateTodos(List<Map<String, Object>> list, BaseListResult result) {
        List<ToDoModel> todos = new ArrayList<>();
        for (Map<String, Object> item : list) {
            ToDoModel model = new ToDoModel();
            // 记录数
            String rowCount = item.get(HSOutputParameterNames.ROWCOUNT).toString();
            if (!StringUtil.isEmpty(rowCount)) {
                result.setRowCount(Long.parseLong(rowCount));
            } else {
                return todos;
            }
            // 总记录数
            String totalCount = item.get(HSOutputParameterNames.TOTAL_COUNT).toString();
            if (!StringUtil.isEmpty(totalCount)) {
                result.setTotalCount(Long.parseLong(totalCount));
            }

            model.setSerialNo(item.get(HSOutputParameterNames.TODO_SERIAL_NO).toString());
            model.setWarningType(item.get(HSOutputParameterNames.WARNING_TYPE).toString());
            model.setBusinessCode(item.get(HSOutputParameterNames.FUND_BUSIN_CODE).toString());
            model.setFundCode(item.get(HSOutputParameterNames.FUND_CODE).toString());
            model.setPlaceHolder(item.get(HSOutputParameterNames.PLACE_HOLDER).toString());
            model.setProtocolName(item.get(HSOutputParameterNames.PROTOCOL_NAME).toString());
            model.setAlloNo(item.get(HSOutputParameterNames.ALLOT_NO).toString());

            todos.add(model);
        }

        return todos;
    }

    /**
     * 组装待办事项内容
     *
     * @param source
     * @param placeHolder
     * @return
     */
    public static String buildTodoConent(String source, String placeHolder) {
        try {
            System.out.println(source);
            String[] array = placeHolder.split("\\|");
            for (String blocker :
                array) {
                String[] items = blocker.split(":");
                String finder = "{" + items[0] + "}";
                String replacer = items[1].trim();
                source = source.replace(finder, replacer);
                System.out.println("finder=" + finder + ",replacer=" + replacer + ",source=" + source);
            }

            return source;
        } catch (Exception ex) {
            logger.error(ExceptionUtil.getMessage(ex));
            throw new BaseException(ErrorConstant.ERROR_CLIENT_NO_FIND);
        }
    }

    /**
     * 根据警示类型查询警示内容
     *
     * @param warnings
     * @param warningType
     * @return
     */
    public static WarningModel getWarning(List<WarningModel> warnings, String warningType) {
        if (!CollectionUtils.isEmpty(warnings)) {
            for (WarningModel model :
                warnings) {
                if (model.getWarningType().equals(warningType)) {
                    return model;
                }
            }
        }

        return null;
    }

    public static String getStatusString(ApplyModel applyModel) {
        if (!applyModel.getIsOrg()) {
            if (applyModel.getFundBusinCode().equals(GlobalConstant.FUND_BUSIN_CODE_APPLY_BUY)) {
                if (applyModel.getTAConfirmFlag().equals(GlobalConstant.TACONFIRM_FLAG_UNCONFIRM)) {
                    if (applyModel.getDeductStatus().equals(GlobalConstant.DEDUCT_STATUS_SENT)) {
                        return GlobalConstant.PERSON_BUY_UNCONFIRM_CHARGED;
                    }
                    if (applyModel.getDeductStatus().equals(GlobalConstant.DEDUCT_STATUS_VALID)) {
                        return GlobalConstant.PERSON_BUY_UNCONFIRM_CHARGEDSUC;
                    }
                    if (applyModel.getDeductStatus().equals(GlobalConstant.DEDUCT_STATUS_INVALID)) {
                        return GlobalConstant.PERSON_BUY_UNCONFIRM_CHARGEDFAIL;
                    }
                }
                if (applyModel.getTAConfirmFlag().equals(GlobalConstant.TACONFIRM_FLAG_FAIL)) {
                    if (applyModel.getDeductStatus().equals(GlobalConstant.DEDUCT_STATUS_VALID)) {
                        return GlobalConstant.PERSON_BUY_CONFIRMFAIL_CHARGEDSUC;
                    }
                    if (applyModel.getDeductStatus().equals(GlobalConstant.DEDUCT_STATUS_INVALID)) {
                        return GlobalConstant.PERSON_BUY_CONFIRMFAIL_CHARGEDFAIL;
                    }
                }
                if (applyModel.getTAConfirmFlag().equals(GlobalConstant.TACONFIRM_FLAG_CONFIRMED)) {
                    if (applyModel.getDeductStatus().equals(GlobalConstant.DEDUCT_STATUS_VALID)) {
                        return GlobalConstant.PERSON_BUY_CONFIRMSUC_CHARGEDSUC;
                    }
                }
                if (applyModel.getTAConfirmFlag().equals(GlobalConstant.TACONFIRM_FLAG_UNDO)) {
                    return GlobalConstant.PERSON_BUY_BACK;
                }
            }
            if (applyModel.getFundBusinCode().equals(GlobalConstant.FUND_BUSIN_CODE_APPLY_SELL)) {
                if (applyModel.getTAConfirmFlag().equals(GlobalConstant.TACONFIRM_FLAG_UNCONFIRM)) {
                    return GlobalConstant.PERSON_SELL_UNCONFIRM;
                }
                if (applyModel.getTAConfirmFlag().equals(GlobalConstant.TACONFIRM_FLAG_CONFIRMED)) {
                    return GlobalConstant.PERSON_SELL_CONFIRMSUC;
                }
                if (applyModel.getTAConfirmFlag().equals(GlobalConstant.TACONFIRM_FLAG_UNDO)) {
                    return GlobalConstant.PERSON_SELL_BACK;
                }
            }
        } else {
            if (applyModel.getFundBusinCode().equals(GlobalConstant.FUND_BUSIN_CODE_APPLY_BUY)) {
                if (applyModel.getTAConfirmFlag().equals(GlobalConstant.TACONFIRM_FLAG_UNCONFIRM)) {
                    if (applyModel.getDeductStatus().equals(GlobalConstant.DEDUCT_STATUS_UNCHECK)) {
                        return GlobalConstant.MECHANISM_BUY_UNCONFIRM_NOCHARGED;
                    }
                    if (applyModel.getDeductStatus().equals(GlobalConstant.DEDUCT_STATUS_VALID)) {
                        return GlobalConstant.MECHANISM_BUY_UNCONFIRM_CHARGEDSUC;
                    }
                    if (applyModel.getDeductStatus().equals(GlobalConstant.DEDUCT_STATUS_INVALID)) {
                        return GlobalConstant.MECHANISM_BUY_UNCONFIRM_CHARGEDFAIL;
                    }
                }
                if (applyModel.getTAConfirmFlag().equals(GlobalConstant.TACONFIRM_FLAG_FAIL)) {
                    if (applyModel.getDeductStatus().equals(GlobalConstant.DEDUCT_STATUS_VALID)) {
                        return GlobalConstant.MECHANISM_BUY_CONFIRMFAIL_CHARGEDSUC;
                    }
                    if (applyModel.getDeductStatus().equals(GlobalConstant.DEDUCT_STATUS_INVALID)) {
                        return GlobalConstant.MECHANISM_BUY_CONFIRMFAIL_CHARGEDFAIL;
                    }
                }
                if (applyModel.getTAConfirmFlag().equals(GlobalConstant.TACONFIRM_FLAG_CONFIRMED)) {
                    if (applyModel.getDeductStatus().equals(GlobalConstant.DEDUCT_STATUS_VALID)) {
                        return GlobalConstant.MECHANISM_BUY_CONFIRMSUC_CHARGEDSUC;
                    }
                }
                if (applyModel.getTAConfirmFlag().equals(GlobalConstant.TACONFIRM_FLAG_UNDO)) {
                    return GlobalConstant.MECHANISM_BUY_BACK;
                }
            }
            if (applyModel.getFundBusinCode().equals(GlobalConstant.FUND_BUSIN_CODE_APPLY_SELL)) {
                if (applyModel.getTAConfirmFlag().equals(GlobalConstant.TACONFIRM_FLAG_UNCONFIRM)) {
                    return GlobalConstant.MECHANISM_SELL_UNCONFIRM;
                }
                if (applyModel.getTAConfirmFlag().equals(GlobalConstant.TACONFIRM_FLAG_CONFIRMED)) {
                    return GlobalConstant.MECHANISM_SELL_CONFIRMSUC;
                }
                if (applyModel.getTAConfirmFlag().equals(GlobalConstant.TACONFIRM_FLAG_UNDO)) {
                    return GlobalConstant.MECHANISM_SELL_BACK;
                }
            }
        }
        return "";
    }


    /**
     * populate组合调仓出参
     *
     * @param result
     * @return
     */
    public static HsCombTransferTradeResponse populateTransfer(Map<String, Object> map, BaseResult result) {
        HsCombTransferTradeResponse model = new HsCombTransferTradeResponse();

        model.setAllot_no(map.get(HSOutputParameterNames.ALLOT_NO).toString());
        model.setApply_date(map.get(HSOutputParameterNames.APPLY_DATE).toString());
        model.setProof_no(map.get(HSOutputParameterNames.PROOF_NO).toString());
        model.setSuccess_type(map.get(HSOutputParameterNames.SUCCESS_TYPE).toString());
        return model;
    }
}
